let limit = 20;
let skip = 0;
var that;
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[]
  },
  nav_guanli(e){
    console.log(e.currentTarget.id)
    if (e.currentTarget.id == 0) {
      wx.redirectTo({
        url: '/pages/administration/shenhe/shenhe',
      })
    }else if (e.currentTarget.id == 1) {
      wx.redirectTo({
        url: '/pages/administration/chat_list/chat_list',
      })
    }else if (e.currentTarget.id == 2) {
      wx.redirectTo({
        url: '/pages/administration/invitation_list/invitation_list',
      })
    }
  },
  async kaiqi(e){
    console.log('e',e)
    var item = this.data.list[e.currentTarget.id];
    var guanbiChat;
    if(!item.guanbiChat){
      guanbiChat = true
    }else{
      guanbiChat = false

    }
    var res = await app.DB.collection('friends').doc(item._id).update({
      data: {
        guanbiChat: guanbiChat
      }
    })
    console.log('res',res,guanbiChat)
    if(res.stats.updated==1){
      wx.showToast({
        title: '操作成功',
        icon:'none'
      })
      this.getData(true)

    }
  },
  zhuangtai(status){
    if(status==1){
      return '已同意'
    }else if(status ==2){
      return '已拒绝'
    }else{
      return '待确认'
    }
  },
  onLoad() {
    that =this
    this.getData()
  },
  getData(inti=false){
    
    app.DB.collection('friends')
      .where({})
      .skip(skip)
      .limit(limit)
      .get()
      .then(res => {
        console.log('getFriends-res', res)
        res.data.forEach(item=>{
          item.status = this.zhuangtai(item.status)
        })
        let list=res.data;
        if(!inti){
          list =[...that.data.list, ...res.data]
        }
        that.setData({
          list: list, //合并数据
          isEndOfList: res.data.length < limit ? true : false //判断是否结束
        })
      })
  },
  onReachBottom: function () {
    !that.data.isEndOfList && that.getData()
  },
})